package com.ruoyi.task.service.impl;

import com.ruoyi.common.exception.base.BaseException;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.task.mapper.ChannelConfigMapper;
import com.ruoyi.task.domain.ChannelConfig;
import com.ruoyi.task.service.IChannelConfigService;

/**
 * 通道配置Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-19
 */
@Service
public class ChannelConfigServiceImpl implements IChannelConfigService 
{
    @Autowired
    private ChannelConfigMapper channelConfigMapper;

    /**
     * 查询通道配置
     * 
     * @param channelId 通道配置主键
     * @return 通道配置
     */
    @Override
    public ChannelConfig selectChannelConfigByChannelId(Long channelId)
    {
        return channelConfigMapper.selectChannelConfigByChannelId(channelId);
    }

    /**
     * 查询通道配置列表
     * 
     * @param channelConfig 通道配置
     * @return 通道配置
     */
    @Override
    public List<ChannelConfig> selectChannelConfigList(ChannelConfig channelConfig)
    {
        return channelConfigMapper.selectChannelConfigList(channelConfig);
    }

    /**
     * 新增通道配置
     * 
     * @param channelConfig 通道配置
     * @return 结果
     */
    @Override
    public int insertChannelConfig(ChannelConfig channelConfig)
    {
        channelConfig.setCreateTime(DateUtils.getNowDate());
        int count = channelConfigMapper.queryChannelConfig(null, channelConfig.getEquipmentId(),
                channelConfig.getEquipmentChannel());
        if (count > 0) {
            throw new BaseException("存在重复的通道号");
        }
        return channelConfigMapper.insertChannelConfig(channelConfig);
    }

    /**
     * 修改通道配置
     * 
     * @param channelConfig 通道配置
     * @return 结果
     */
    @Override
    public int updateChannelConfig(ChannelConfig channelConfig)
    {
        channelConfig.setUpdateTime(DateUtils.getNowDate());
        int count = channelConfigMapper.queryChannelConfig(channelConfig.getChannelId(),
                channelConfig.getEquipmentId(),
                channelConfig.getEquipmentChannel());
        if (count > 0) {
            throw new BaseException("存在重复的通道号");
        }
        return channelConfigMapper.updateChannelConfig(channelConfig);
    }

    /**
     * 批量删除通道配置
     * 
     * @param channelIds 需要删除的通道配置主键
     * @return 结果
     */
    @Override
    public int deleteChannelConfigByChannelIds(Long[] channelIds)
    {
        return channelConfigMapper.deleteChannelConfigByChannelIds(channelIds);
    }

    /**
     * 删除通道配置信息
     * 
     * @param channelId 通道配置主键
     * @return 结果
     */
    @Override
    public int deleteChannelConfigByChannelId(Long channelId)
    {
        return channelConfigMapper.deleteChannelConfigByChannelId(channelId);
    }
}
